package com.wondertek.common.i18n;

import cn.hutool.core.util.ReflectUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.wondertek.common.dict.AutoDict;
import com.wondertek.common.dict.AutoDictService;
import com.wondertek.common.util.base.MessageUtils;

import java.lang.reflect.Field;

/**
 * 国际化工具类
 */
public class AutoLangUtil {

    public static void lang(Object obj) {
        Field[] fields = ReflectUtil.getFields(obj.getClass());
        for (Field field : fields) {
            AutoLang autoLang = field.getAnnotation(AutoLang.class);
            if (autoLang != null) {
                String fieldName = autoLang.field();
                Object fieldValue = ReflectUtil.getFieldValue(obj, autoLang.field());
                if(fieldValue instanceof String){
                    String value = MessageUtils.getMessage((String) fieldValue);
                    ReflectUtil.setFieldValue(obj, field, value);
                }
            }
        }
    }
}
